package com.atguigu.educms.controller;


import com.atguigu.commonutils.pojo.R;
import com.atguigu.educms.entity.CrmBanner;
import com.atguigu.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 后端控制器
 * </p>
 *
 * @author 东渡素玄
 * @since 2022-09-16
 */
@RestController
@RequestMapping("/educms/banneradmin")
@CrossOrigin
public class BannerAdminController {
    @Resource
    private CrmBannerService crmBannerService;

    @ApiOperation(value = "分页查banner")
    @GetMapping("/pageBanner/{page}/{limit}")
    public R pageBanner(@PathVariable Long page, @PathVariable Long limit){
        Page<CrmBanner> crmBannerPage=new Page<>(page,limit);
        crmBannerService.page(crmBannerPage,null);
        return R.ok().data("items",crmBannerPage.getRecords()).data("total",crmBannerPage.getTotal());
    }

    //获取banner
    @ApiOperation(value = "获取banner")
    @DeleteMapping("/get{id}")
    public R get(@PathVariable String id){
        CrmBanner crmBanner = crmBannerService.getById(id);
        return R.ok().data("item",crmBanner);
    }

    //添加banner
    @ApiOperation(value = "添加banner")
    @PostMapping("/addBanner")
    public R addBanner(@RequestBody CrmBanner crmBanner){
        crmBannerService.save(crmBanner);
        return R.ok();
    }
    //修改banner
    @ApiOperation(value = "修改banner")
    @PostMapping("/update")
    public R updateById(@RequestBody CrmBanner crmBanner){
        crmBannerService.updateById(crmBanner);
        return R.ok();
    }
    //删除banner
    @ApiOperation(value = "删除banner")
    @DeleteMapping("/delete/{id}")
    public R deleteBanner(@PathVariable Integer id){
        crmBannerService.removeById(id);
        return R.ok();
    }
}

